package org.phalanx.client.loadupdialog;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.phalanx.client.UI.PhalanxIconButton;

public class MainMenuScreen extends JFrame implements ActionListener {
	static final long serialVersionUID = 100l;
	private int width = 700;
	private int height = 400;
	private JPanel menuPanel;
	private JPanel leftPanel;
	private String startPlay = "Play";
	private String exitClient = "Exit";
	public static final String NAME = "MainMenuScreen";
	
	public MainMenuScreen (){
		init();
	}
	
	public void init(){
		setUpComponents();
		setUpWindowProperties();
		this.setSize(900, 700);
		//this.setVisible(true);
	}
	
	private void setUpWindowProperties(){
		this.setSize(width, height);
		this.setBackground(Color.black);
		
		JPanel containerPanel = setupWindowPanel();
		containerPanel.add(leftPanel);
		containerPanel.add(menuPanel);
		this.add(containerPanel);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	private void setUpComponents(){
		setUpMenuPanel();
		setupLeftPanel();
	}
	
	private void setupLeftPanel(){
		leftPanel = new JPanel();
		leftPanel.setLayout(new BoxLayout(leftPanel,BoxLayout.X_AXIS));
		/*JButton testButton = new JButton(ImageFactory.getInstance().getImageIcon("resources/images/Greek_Phalanx.jpg"));
		testButton.setText("test");
		testButton.setBackground(Color.black);*/
		leftPanel.add(getPhalanxButton("testing"));
		leftPanel.setBackground(Color.black);
		leftPanel.setSize(400,300);
	}
	
	private PhalanxIconButton getPhalanxButton(String text){
		PhalanxIconButton p = new PhalanxIconButton();
		p.setDefaultIcon(new ImageIcon("/home/sday/phalanxArt/Army.png"));
		p.setHoveredIcon(new ImageIcon("/home/sday/phalanxArt/Army1.png"));
		p.setClickedIcon(new ImageIcon("/home/sday/phalanxArt/HeavyScout.png"));
		p.setText(text);
		return p;
		
	}
	
	private JPanel setupWindowPanel(){
		JPanel containerPanel = new JPanel();
		containerPanel.setLayout(new BoxLayout(containerPanel,BoxLayout.X_AXIS));
		containerPanel.setBackground(Color.black);
		return containerPanel;
	}
	
	private void setUpMenuPanel(){
		menuPanel = new JPanel();
		menuPanel.setLayout(new BoxLayout(menuPanel,BoxLayout.Y_AXIS));
		PhalanxIconButton exitButton = getPhalanxButton(exitClient);
		menuPanel.add(getPhalanxButton(startPlay));
		menuPanel.add(exitButton);
		menuPanel.setSize(800, height);
		menuPanel.setBorder(BorderFactory.createBevelBorder(1));
		
		for (int i = 0; i < menuPanel.getComponentCount(); i++){
			if (menuPanel.getComponent(i) instanceof JButton){
				JButton menuButtons = (JButton)menuPanel.getComponent(i);
				menuButtons.addActionListener(this);
				menuButtons.setSize(menuPanel.getWidth(), menuButtons.getHeight());
			}
		}
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() instanceof PhalanxIconButton){
			PhalanxIconButton p = (PhalanxIconButton) e.getSource();
			if (p.getText().equals("exitClient")){
				System.exit(0);
			}
		}
	}
}
